const http = require('http');
const fs = require('fs');

http.createServer((req, res)=>{
    //http://localhost:8001/news.html    /news.html
	//http://localhost:8001/index.html    /index.html
    let pathname = req.url;
    if(pathname == '/'){
        pathname = '/index.html';   //默认加载首页
    }
    if(pathname != '/favicon.ico'){
        console.log(pathname);
        //过滤请求的favicon.ico
        fs.readFile('static/' + pathname, (err, data)=>{
            if(err){
                console.log(err);
            }
            else{
                res.writeHead(200, {"Content-Type":"text/html;charset='utf-8'"});
                res.write(data);
                res.end();
            }
        });
    }
}).listen(8001);